package org.example
import scala.io.Source
import scala.util.Try

case class Employee(empID: Int, name: String, gender: String, dateOfBirth: String, age: Int, gross: Double, netPay: Double, deduction: Double, designation: String, department: String)

object TopSalaries extends App {
  val filename = "E:\\23yunji2\\Employee_salary_first_half.csv"
  val lines = Source.fromFile(filename).getLines().toList
  val employees = lines.tail.map { line =>
    val cols = line.split(",").map(_.trim)
    Employee(
      empID = cols(0).toInt,
      name = cols(1),
      gender = cols(2),
      dateOfBirth = cols(3),
      age = cols(4).toInt,
      gross = cols(5).toDouble,
      netPay = cols(6).toDouble,
      deduction = cols(7).toDouble,
      designation = cols(8),
      department = cols(9)
    )
  }
  val topThree = employees.sortBy(-_.gross).take(3)
  println("Top 3 Employees by Gross Salary:")
  topThree.foreach { emp =>
    println(s"EmpID: ${emp.empID}, Name: ${emp.name}, Gross Salary: ${emp.gross}, Net Pay: ${emp.netPay}, Department: ${emp.department}")
  }
}
